<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Search.php 2010-08-31 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Page_Form_Search extends Fields_Form_Search
{
	protected $_fieldType = 'page';
	
	public function init()
  {
  	parent::init();
  	
  	$this->generate();
  	$this->loadDefaultDecorators();
  	
  	$subform = new Zend_Form_SubForm(array(
      'order' => -100,
      'decorators' => array(
        'FormElements',
        array('Description', array('placement' => 'PREPEND', 'tag' => 'span')),
        array('HtmlTag', array('tag' => 'li', 'class' => 'browse-range-wrapper'))
      )
    ));
    Engine_Form::enableForm($subform);
          
  	$subform->addElement('Hidden', 'city', array(
    	'order' => -4
    ));
    
    $subform->addElement('Hidden', 'tag_id', array(
    	'order' => -5
    ));
    
    $subform->addElement('Hidden', 'sort', array(
      'order' => -6
    ));
    
  	$subform->addElement('Text', 'keyword', array(
    	'order' => -3,
  		'decorators' => array(
        'ViewHelper',
        array('HtmlTag', array('tag' => 'li'))
      ),   	
    ));
    
    $this->addElement('Button', 'submit', array(
    	'label' => 'Search',
    	'order' => 10000,
    	'type' => 'submit',
    	'decorators' => array(
        'ViewHelper',
        array('HtmlTag', array('tag' => 'li'))
      ),
    ));
    
    $this->addSubForm($subform, 'extra');
    $this->addAttribs(array('id' => 'filter_form', 'class' => 'global_form_box'));
    $this->getPageTypeElement();
  }
  
	public function getPageTypeElement()
  {
    $multiOptions = array('' => ' ');
    $profileTypeFields = Engine_Api::_()->fields()->getFieldsObjectsByAlias($this->_fieldType, 'profile_type');
    if( count($profileTypeFields) !== 1 || !isset($profileTypeFields['profile_type']) ) return;

    $options = $profileTypeFields['profile_type']->getOptions();
    if( count($options) <= 1 ) {
      return;
    }

    foreach( $options as $option ) {
      $multiOptions[$option->option_id] = $option->label;
    }

    $this->addElement('Select', 'profile_type', array(
      'label' => 'Page Type',
      'order' => 1,
      'decorators' => array(
        'ViewHelper',
        array('Label', array('tag' => 'span')),
        array('HtmlTag', array('tag' => 'li'))
      ),
      'multiOptions' => $multiOptions,
    ));
    return $this->profile_type;
  }
}